<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of OptionalFieldsElement
 *
 * @author julien
 */
require_once 'Classes/Element.php';
class OptionalFieldsElement extends Element{
    protected $Optional_1="";
    protected $Optional_2="";
    protected $Optional_3="";
    protected $Optional_4="";
    protected $Optional_5="";
    protected $Optional_6="";
    
    
     public function __construct($arrayOrId,$name="",$optional_1="",$optional_2="",
                                $optional_3="",$optional_4="",$optional_5="",$optional_6="") {
        parent::__construct($arrayOrId);
        
        if(is_array($arrayOrId)){    
            
            $this->Optional_1 = $arrayOrId['Optional_1'];
            $this->Optional_2 = $arrayOrId['Optional_2'];
            $this->Optional_3 = $arrayOrId['Optional_3'];
            $this->Optional_4 = $arrayOrId['Optional_4'];
            $this->Optional_5 = $arrayOrId['Optional_5'];
            $this->Optional_6 = $arrayOrId['Optional_6'];
            
        }
        else{
            
            $this->Optional_1 = $optional_1;
            $this->Optional_2 = $optional_2;
            $this->Optional_3 = $optional_3;
            $this->Optional_4 = $optional_4;
            $this->Optional_5 = $optional_5;
            $this->Optional_6 = $optional_6;
        }
    }
    
    
    protected function splitOptionnalField($field){
        $splitedArray = array();
        $splitedArray = preg_split("/:/", $field);
        for($i = 0; $i<2; $i++){
            if(!isset ($splitedArray[$i])){
                $splitedArray[$i]= null;
            }
        }
    return array($splitedArray[0] => $splitedArray[1]);
    }
    
      public function getOptional_1(){
        return  $this->splitOptionnalField($this->Optional_1);
    }
    
    public function setOptional_1($Optional_1){
        $this->Optional_1= $Optional_1;
       
    }
    
    public function getOptional_2(){
        return  $this->splitOptionnalField($this->Optional_2);
    }   
    
    public function setOptional_2($Optional_2){
       
        $this->Optional_2= $Optional_2;
        
    }
      
    public function getOptional_3(){
        return  $this->splitOptionnalField($this->Optional_3);
    }
    
    public function setOptional_3($Optional_3){
        $this->Optional_3= $Optional_3;
        
    }
    
    
    public function getOptional_4(){
        return  $this->splitOptionnalField($this->Optional_4);
    }
    
    public function setOptional_4($Optional_4){
        
        $this->Optional_4= $Optional_4;
        
    }
    
    
    public function getOptional_5(){
         return  $this->splitOptionnalField($this->Optional_5);

    }
    
    public function setOptional_5($Optional_5){
        
        $this->Optional_5= $Optional_5;
       
    }
    
    
    public function getOptional_6(){
         return  $this->splitOptionnalField($this->Optional_6);

    }
    
    public function setOptional_6($Optional_6){
        
        $this->Optional_6= $Optional_6;
        
    }
    
    public function getOptionalFields(){
        $optionalFields = $this->getOptional_1();

        
        $optionalFields = array_merge($optionalFields, $this->getOptional_2());
        $optionalFields = array_merge($optionalFields, $this->getOptional_3());
        $optionalFields = array_merge($optionalFields, $this->getOptional_4());
        $optionalFields = array_merge($optionalFields, $this->getOptional_5());
        $optionalFields = array_merge($optionalFields, $this->getOptional_6());
        
        
        // Epuration des null
        foreach ($optionalFields as $key => $value) {
            if(is_null($value)){
                unset($optionalFields[$key]);
            }
        }
        
        return $optionalFields;
    }
    
    
}

?>
